<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Api\Controller;
use App\Http\Requests\Api\OrderRequest;
use App\Models\Order;
use App\Transformers\GoodsinfoTransformer;
use App\Transformers\OrderTransformer;
use Illuminate\Http\Request;



class OrderController extends Controller
{
    //订单列表页
    public function index(OrderRequest $request,Order $order){

        $query=$order->newQuery();
        $result=$request->all();
        $where=[];
        if (!empty($result['order_type'])){
            $query->where('order_type','like','%' . $result['order_type'] . '%');
        }
        if (!empty($result['status'])){
            $query->where('status','like','%' . $result['status'] . '%');
        }
        if (!empty($result['payment_status'])){
            $query->where('payment_status','like','%' . $result['payment_status'] . '%');
        }
        if (!empty($result['order_ship'])){
            $query->where('order_ship','like','%' . $result['order_ship'] . '%');
        }
        if (!empty($result['goods_name'])){
            $query->where('goods_name','like','%' . $result['goods_name'] . '%');
        }

        $orders=$query->paginate(20);

       return $this->response->paginator($orders,new OrderTransformer());
    }

    //订单删除
    public function destory(Order $order){
        $result=$order->delete();
        if ($result){
            return $this->response->array(['message'=>'删除成功'])->setStatusCode(204);
        }else{
            return $this->response->array(['message'=>'删除失败']);
        }
    }

    //订单详情
    public function edit(Order $order){

        return $this->response->item($order,new OrderTransformer());
    }
}
